package io.renren.minimito.service.impl;

import io.renren.minimito.entity.SqTagEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.minimito.dao.SqActivityDao;
import io.renren.minimito.entity.SqActivityEntity;
import io.renren.minimito.service.SqActivityService;
import org.springframework.util.StringUtils;


@Service("sqActivityService")
public class SqActivityServiceImpl extends ServiceImpl<SqActivityDao, SqActivityEntity> implements SqActivityService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SqActivityEntity> page = this.page(
                new Query<SqActivityEntity>().getPage(params),
                new QueryWrapper<SqActivityEntity>()
        );

        return new PageUtils(page);
    }

    //活动管理模糊查询
    @Override
    public PageUtils queryPageByCondition(Map<String, Object> params) {
        QueryWrapper<SqActivityEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.and((w)->{
                w.eq("id",key).or().like("title",key)
                        .or().like("address",key)
                        .or().like("begin_time",key)
                        .or().like("end_time",key)
                        .or().like("activity_status",key)
                        .or().like("local_city",key)
                        .or().like("local_detail",key)
                        .or().like("tags",key)
                        .or().like("initiator_id",key);
            });
        }
        IPage<SqActivityEntity> page = this.page(
                new Query<SqActivityEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);

    }

}